package com.mes.cloud.base.controller;

import com.enbatis.mybatisplugs.base.Account;
import com.enbatis.mybatisplugs.base.BaseController;
import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.commons.utils.CodeMsg;
import com.enbatis.mybatisplugs.commons.utils.MD5Util;
import com.enbatis.mybatisplugs.commons.utils.ResultReturn;
import com.enbatis.mybatisplugs.toolkit.LoginCacheUtil;
import com.mes.cloud.base.service.SysUserService;
import com.mes.cloud.feign.base.SysUserFeign;
import com.mes.cloud.commons.entity.base.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("v1/sys_user")
@Slf4j
public class SysUserController extends BaseController implements SysUserFeign {

@Autowired
private SysUserService sysUserService;

    @Value("${server.port}")
    private String port ;


    @PostMapping("/add")
    public ResultReturn<SysUser> add(@RequestBody SysUser sysUser){
        return  success(sysUserService.insert(sysUser));
    }


    @DeleteMapping("/delete")
    public ResultReturn<Integer> delete(@RequestParam("id") Long id){
        return success(sysUserService.deleteById(id));
    }


    @PutMapping("/{id}")
    public  ResultReturn<Integer> update(@PathVariable("id") Long id,@RequestBody SysUser sysUser){
        sysUser.setId(id);
        return success(sysUserService.updateById(sysUser));
    }


    @Override
    @GetMapping("/{id}")
    public ResultReturn get(@PathVariable("id") Long id) {
        return success(sysUserService.getById(id));
    }


    @Override
    @GetMapping("/user_get/{id}")
    public ResultReturn getUser(@PathVariable("id") Long id) {
        SysUser sysUser= sysUserService.getById(id);
        sysUser.setPassword(port);
        return success(sysUser);
    }


    @GetMapping("/list")
    public ResultReturn<List<SysUser>> getList(SysUser sysUser){
        return success(sysUserService.list(new Wrapper<>(sysUser)));
    }


    @GetMapping("/login")
    public ResultReturn login(){

        return  sysUserService.login(new SysUser(),request,response);

    }

}
